package com.example.reggie.common;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.reggie.entity.Employee;
import com.example.reggie.entity.Log;
import com.example.reggie.entity.User;
import com.example.reggie.service.EmployeeService;
import com.example.reggie.service.LogService;
import com.example.reggie.service.UserService;
import io.swagger.models.auth.In;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

@Aspect
@Component
public class MyLog {

    @Autowired
    private LogService logService;

    @Autowired
    private UserService userService;
    @Pointcut("@annotation(com.example.reggie.common.annotation.Log)")
    public void logPointCut() {
    }

    @AfterReturning(value = "logPointCut()")
    public void doAfterThrowing(JoinPoint joinPoint) {
        Log log = new Log();

        Date date = new Date();
//        String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        log.setDate(date);

        logService.save(log);
    }



    /*设置当前通知方法与切入点之间的绑定关系，当前通知方法在原始切入点方法正常执行完毕后运行*/

}
